import { Controller, Get, Query, Res } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { UserService } from '@/pmp/system/services/user/user.service';

@ApiTags('导入')
@Controller('download')
export class DownloadController {
  constructor(private readonly userService: UserService) {}

  @ApiOperation({ summary: '下载导入模板' })
  @Get(`/template`)
  template(@Res() res: Response, @Query('name') name: string) {
    console.log(name);
    res.setHeader('Cache-Control', 'no-store');
    res.setHeader('Pragma', 'no-cache');
    res.setHeader('Expires', '0');
    res.setHeader('Content-Type', 'application/octet-stream');
    res.setHeader(
      'Content-Disposition',
      'attachment; filename="import_template.xlsx"',
    );
    res.status(200);
    if (name === 'user') {
      return res.send(this.userService.generateTemplate());
    }
  }
}
